luogu2278 [HNOI2003]操作系统

1
2
3
4
5
6
7
8
好久没写重载了
less需要重载小于号
greater需要重载大于号
stl中使用结构体会使成员变量变成private,导致只可访问,不可修改
所以成员函数要加const
priority_queue:从小到大排序后每次取最后一个
sort/set:从小到大排序
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return x*f;
}
int id,t1,t2,a,pre;
struct node{
int x,y,z;
inline bool operator < (const node &a) const{
if(x!=a.x) return x<a.x;
return y>a.y;
}
};
priority_queue<node> q;
int main()
{
while(scanf("%d",&id)!=EOF){
t1=read();t2=read();a=read();
if(q.empty()){
q.push((node){a,id,t2});
pre=t1;
}
else{
while(!q.empty()&&pre+q.top().z<=t1){
pre+=q.top().z;
printf("%d %d\n",q.top().y,pre);
q.pop();
}
if(!q.empty()&&pre<t1){
node t=q.top();
q.pop();
t.z-=t1-pre;
q.push(t);
}
q.push((node){a,id,t2});
pre=t1;
}
}
while(!q.empty()){
pre+=q.top().z;
printf("%d %d\n",q.top().y,pre);
q.pop();
}
return 0;
}